using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Plugin.Sns.Scene;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.ImageFilter;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
namespace MicroMsg.UI.Page
{
	public class CircleMainPage : BasePage
	{
		private enum CircleMPageBarMode
		{
			Mode_None,
			Mode_Defalut,
			Mode_BigPic
		}
		public delegate void UnDoDlg();
		private class CommentTask
		{
			public SnsInfo mSnsInfo;
			public string mStrContent;
			public CommentType mType;
			public AddContactScene mScene;
			public int mNReplyId;
			public int mCommentId;
			public string mStrReplyName;
		}
		private const string TAG = "CircleMainPage";
		private const double cNMaxRCnt = 0.5;
		private const double cDOriginRefreshIconYOffset = -78.0;
		private const double cDMaxRefreshIconYOffset = 0.0;
		private const double cDMiniRefreshOffset = 100.0;
		private const double cDScrollEndHeight = 848.0;
		private const int cNRefreshIconMoveRDur = 900;
		private const int cNRefreshIconMoveYDur = 600;
		private const string ScrollingState = "Scrolling";
		private const string NotScrollingState = "NotScrolling";
		public const int cNAblumEndID = 0;
		private const int nExpandDuration = 150;
		public const string strKeyNInCircleCnt = "strKeyNInCircleCnt";
		private ObservableCollection<SnsInfo> mListBoxSource;
		private static CircleMainPage sInstance = null;
		private SnsPageSource pageSrc;
		private SnsInfo lastestSnsInfo;
		private bool mBIsLayoutUpdated;
		private bool mBIsFirstLoaded = true;
		private bool mBIsPageLoaded;
		private bool mBIsPageFirstLoaded = true;
		private bool mBIsDataCleared;
		private EventWatcher mWatchTimeLine;
		private object mObjectWatcher = new object();
		private bool mBIsDragRefIconStart;
		private Point mPMouseStart = new Point(-1000.0, -1000.0);
		private double mDLastOffset;
		private double mDVerticalOffset;
		private Point mPosCommentItem;
		private TimelineItem mItemForComment;
		private ApplicationBar mBar;
		private CircleMainPage.CircleMPageBarMode mCurBarmode;
		private bool mBIsTopRefreshAniStarted;
		private Storyboard mSbTopRefresh;
		private bool mBTopRefreshYMoveStarted;
		private bool mBIsEndTopRefreshAniStarted;
		private Storyboard mSbEndTopRefresh;
		private bool mBIsNeedEndTopRefresh;
		private ScrollViewer mScrollViewer;
		private bool mBIsScrollHandlerSet;
		private bool mBIsScrolling;
		private bool mBIsListendRendering;
		private DateTime mTimeLastRefresh = DateTime.get_Now();
		private bool mBIsInTop = true;
		public static string cStrAblumCoverID = SnsInfo.toStrID(18446744073709551615uL);
		private bool mBHasExpandedFun;
		private TimelineItem mItemExpanded;
		private bool mBIsFisrtExpandItemFuncs = true;
		private bool mBIsItemFuncsAniStarted;
		private Storyboard mSbExpandImg;
		private static FrameworkElement sCtrlListTail = null;
		private DateTime mTimeLastRefEnd = DateTime.get_Now();
		private static bool sBIsTailShowRefreshing = false;
		private bool mBIsBackKeyEnabled = true;
		private static bool sBIsUndoLocked = false;
		private List<CircleMainPage.UnDoDlg> listUndos = new List<CircleMainPage.UnDoDlg>();
		private int mNdoUnDoLevel;
		private List<CircleMainPage.UnDoDlg> mUndoIgnore = new List<CircleMainPage.UnDoDlg>();
		private bool mBIsInputerShown;
		private CircleMainPage.CommentTask mCmtsToSend;
		private int mNOffSetAppend;
		private DispatcherTimer mTimerGoTop;
		private UserHeadCtrl mHeadCtrl;
		private bool mBIsInputerInited;
		private bool isInputFocus;
		internal Grid LayoutRoot;
		internal MMListBox listBoxTimelines;
		internal Grid gridExpandFuncAni;
		internal Grid gridExpandClipConer;
		internal RectangleGeometry rectFuncsClip;
		internal Button btnLike;
		internal Image imgLike;
		internal ScaleTransform transformBtnLike;
		internal TextBlock txtFuncLike;
		internal Button btnComment;
		internal Image imgCmt;
		internal ScaleTransform transformBtnCmt;
		internal TextBlock txtFuncCmt;
		internal TranslateTransform transformFuncs;
		internal ClickEffectGrid gridGoTop;
		internal MMInputer mInputer;
		internal Canvas canvasRefreshArea;
		internal CompositeTransform transRefeshIcon;
		internal TextBlock txtNoData;
		private bool _contentLoaded;
		public bool IsScrolling
		{
			get;
			private set;
		}
		public static CircleMainPage GetInstance()
		{
			return CircleMainPage.sInstance;
		}
		public CircleMainPage()
		{
			this.InitializeComponent();
			CircleMainPage.sInstance = this;
			base.add_Loaded(new RoutedEventHandler(this.Page_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Page_Unloaded));
			this.listBoxTimelines.set_ItemsSource(this.mListBoxSource);
			this.listBoxTimelines.mListBoxKind = MMListBoxKind.Kind_Timeline;
			this.setAppBar(CircleMainPage.CircleMPageBarMode.Mode_Defalut);
			base.add_LayoutUpdated(new EventHandler(this.CircleMainPage_LayoutUpdated));
		}
		private void CircleMainPage_LayoutUpdated(object sender, EventArgs e)
		{
			if (this.mBIsLayoutUpdated)
			{
				return;
			}
			this.mBIsLayoutUpdated = true;
			base.remove_LayoutUpdated(new EventHandler(this.CircleMainPage_LayoutUpdated));
		}
		private void tryDoRecycle()
		{
			if (!SnsRecycleMgr.needDoRecycle())
			{
				return;
			}
			ProcessingCover.getProgressBar(this.LayoutRoot, strings.Album_Recycling, null, false, false, null);
			PhoneApplicationService.get_Current().set_UserIdleDetectionMode(1);
			SnsRecycleMgr.doRecycleStart(delegate
			{
				ProcessingCover.releaseProgressBar(this.LayoutRoot);
				PhoneApplicationService.get_Current().set_UserIdleDetectionMode(0);
			});
		}
		private void showMoreTimelines()
		{
			if (this.mBIsDataCleared)
			{
				return;
			}
			this.showTimeline(40);
		}
		private void pageLoadedProc()
		{
			if (this.mBIsGoingToMainPageFromTombstone)
			{
				return;
			}
			this.tryDoRecycle();
			if (this.mBIsDataCleared)
			{
				return;
			}
			if (this.mBIsFirstLoaded)
			{
				this.initTimeLinePage();
				base.get_Dispatcher().BeginInvoke(delegate
				{
					List<UITask> list = new List<UITask>();
					list.Add(new UITask(new UITaskDlg(this.showMoreTimelines), 0u));
					UITaskManager uITaskManager = new UITaskManager(list, null);
					uITaskManager.StartTasks(500u);
					SnsPostService.resumeUploadAndPost();
				});
				this.mBIsFirstLoaded = false;
			}
			this.mBIsPageLoaded = true;
			Log.smethod_5("CircleMainPage", "Page_Loaded");
			this.setScrollHandler();
			this.showAppBar();
		}
		private void Page_Loaded(object sender, RoutedEventArgs e)
		{
			this.mBIsPageLoaded = true;
			Touch.add_FrameReported(new TouchFrameEventHandler(this.Touch_FrameReported));
			base.BeginListenForSIPChanged();
			this.ClearTransition();
			if (this.mBIsPageFirstLoaded)
			{
				this.addSnsInfos(new List<SnsInfo>());
				base.get_Dispatcher().BeginInvoke(delegate
				{
					this.pageLoadedProc();
				});
				this.mBIsPageFirstLoaded = false;
			}
		}
		private void Page_Unloaded(object sender, RoutedEventArgs e)
		{
			if (this.mBIsDataCleared)
			{
				base.remove_Unloaded(new RoutedEventHandler(this.Page_Unloaded));
			}
			this.mBIsPageLoaded = false;
			Log.smethod_5("CircleMainPage", "Page_Unloaded");
			Touch.remove_FrameReported(new TouchFrameEventHandler(this.Touch_FrameReported));
			base.EndListenForSipChanged();
			this.stopListenRendering();
			this.hideAppBar();
		}
		private void initTimeLinePage()
		{
			if (this.mBIsDataCleared)
			{
				return;
			}
			this.registerEvent();
			if (this.listBoxTimelines == null)
			{
				return;
			}
			this.listBoxTimelines.add_ManipulationStarted(new EventHandler<ManipulationStartedEventArgs>(this.listBoxTimelines_ManipulationStarted));
			this.pageSrc = SnsPageMgr.getPageSrc(SnsPageMgr.TimeLineUserName);
			this.pageSrc.refreshFirsPage();
			this.initUI();
			if (TimelineItemContainer.sAlbumCoverCtrl != null)
			{
				TimelineItemContainer.sAlbumCoverCtrl.RefreshContactHeadImg();
			}
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (this.mBIsGoingToMainPageFromTombstone)
			{
				return;
			}
			Log.smethod_5("CircleMainPage", "OnPageIn");
			this.tryShowWelcomeCtrl();
		}
		private object listBoxTimelines_mUnLinked(object sender, object object_0)
		{
			if (!this.mBIsDataCleared)
			{
				return null;
			}
			if (object_0 == null || !(object_0 is MMListBoxLinkEventArg))
			{
				return null;
			}
			MMListBoxLinkEventArg mMListBoxLinkEventArg = object_0 as MMListBoxLinkEventArg;
			if (mMListBoxLinkEventArg.mListItem != null && mMListBoxLinkEventArg.mItemObject != null)
			{
				TimelineItemContainer timelineItemContainer = UIElementTraveler.FindFirstElementInVisualTree<TimelineItemContainer>(mMListBoxLinkEventArg.mListItem);
				if (timelineItemContainer != null)
				{
					timelineItemContainer.UnLinked();
				}
				mMListBoxLinkEventArg.mListItem = null;
				mMListBoxLinkEventArg.mItemObject = null;
				return null;
			}
			return null;
		}
		private object listBoxTimelines_mLinked(object sender, object object_0)
		{
			return null;
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("CircleMainPage", "OnPageOut");
			this.clearScrollHandler();
			if (this.listBoxTimelines == null)
			{
				return;
			}
			this.listBoxTimelines.remove_ManipulationStarted(new EventHandler<ManipulationStartedEventArgs>(this.listBoxTimelines_ManipulationStarted));
			this.listBoxTimelines.mLinked -= new MMUIEvent(this.listBoxTimelines_mLinked);
			this.listBoxTimelines.mUnLinked -= new MMUIEvent(this.listBoxTimelines_mUnLinked);
			base.remove_Loaded(new RoutedEventHandler(this.Page_Loaded));
			TimelineItemContainer.CacheAllItems();
			this.unRegisterEvent();
			this.mBIsDataCleared = true;
			if (this.mListBoxSource != null)
			{
				for (int i = 0; i < this.mListBoxSource.get_Count(); i++)
				{
					this.mListBoxSource.set_Item(i, null);
				}
			}
			this.listBoxTimelines.set_ItemsSource(null);
			if (this.listBoxTimelines.get_Parent() != null)
			{
				Panel panel = this.listBoxTimelines.get_Parent() as Panel;
				if (panel != null)
				{
					panel.get_Children().Remove(this.listBoxTimelines);
				}
				this.listBoxTimelines = null;
			}
			CircleMainPage.sInstance = null;
			base.get_Dispatcher().BeginInvoke(delegate
			{
				GC.Collect();
				SendFailedHintsPanel.ClearPanel();
			});
			CircleHubPrevCtrl.getInstance().UpdateCircleHubPreView(this.lastestSnsInfo);
		}
		protected override void OnPageBack()
		{
			Log.smethod_5("CircleMainPage", "OnPageBack");
			this.gridExpandFuncAni.set_Margin(new Thickness(0.0, -100.0, 0.0, 0.0));
			this.gridExpandFuncAni.set_Visibility(0);
			this.hideInputer();
		}
		private void registerEvent()
		{
			if (this.mWatchTimeLine == null)
			{
				this.mWatchTimeLine = new EventWatcher(this.mObjectWatcher, null, new EventHandlerDelegate(this.OnTimeLineEvent));
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_SNSINFO_ADD, this.mWatchTimeLine);
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_SNSINFO_DEL, this.mWatchTimeLine);
				EventCenter.registerEventWatcher(EventConst.ON_STORAGE_SNSINFO_MODIFY, this.mWatchTimeLine);
				EventCenter.registerEventWatcher(EventConst.ON_MGR_SNSPAGE_PAGE_ATTACH_ITEM, this.mWatchTimeLine);
				EventCenter.registerEventWatcher(EventConst.ON_MGR_SNSPAGE_REFRESH_PAGE_START, this.mWatchTimeLine);
				EventCenter.registerEventWatcher(EventConst.ON_MGR_SNSPAGE_REFRESH_PAGE_END, this.mWatchTimeLine);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatchTimeLine != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_SNSINFO_ADD, this.mWatchTimeLine);
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_SNSINFO_DEL, this.mWatchTimeLine);
				EventCenter.removeEventWatcher(EventConst.ON_STORAGE_SNSINFO_MODIFY, this.mWatchTimeLine);
				EventCenter.removeEventWatcher(EventConst.ON_MGR_SNSPAGE_PAGE_ATTACH_ITEM, this.mWatchTimeLine);
				EventCenter.removeEventWatcher(EventConst.ON_MGR_SNSPAGE_REFRESH_PAGE_START, this.mWatchTimeLine);
				EventCenter.removeEventWatcher(EventConst.ON_MGR_SNSPAGE_REFRESH_PAGE_END, this.mWatchTimeLine);
				this.mWatchTimeLine = null;
			}
		}
		private void OnTimeLineEvent(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			if (this.mBIsDataCleared)
			{
				return;
			}
			EventConst mEventID = evtArgs.mEventID;
			switch (mEventID)
			{
			case EventConst.ON_MGR_SNSPAGE_REFRESH_PAGE_START:
				if ((string)evtArgs.mObject != SnsPageMgr.TimeLineUserName)
				{
					return;
				}
				this.startTopRefreshAni();
				return;
			case EventConst.ON_MGR_SNSPAGE_REFRESH_PAGE_END:
			{
				if ((string)evtArgs.mObject != SnsPageMgr.TimeLineUserName)
				{
					return;
				}
				base.get_Dispatcher().BeginInvoke(delegate
				{
					this.startEndRefreshTopAni();
				});
				List<ulong> snsInfoID = this.getSnsInfoID();
				List<SnsInfo> listSnsinfo = this.pageSrc.syncList(snsInfoID);
				if (this.pageSrc.isRefreshAllPageDone())
				{
					CircleMainPage.SetTailPageEnd();
				}
				if (!this.pageSrc.isPageRefreshing())
				{
					CircleMainPage.SetTailNotRefreshing();
				}
				this.mergeList(listSnsinfo, false);
				return;
			}
			case EventConst.ON_MGR_SNSPAGE_PAGE_ATTACH_ITEM:
			{
				List<SnsInfo> listObject = evtArgs.getListObject<SnsInfo>();
				this.addSnsInfos(listObject);
				return;
			}
			default:
				switch (mEventID)
				{
				case EventConst.ON_STORAGE_SNSINFO_ADD:
				{
					List<SnsInfo> listObject2 = evtArgs.getListObject<SnsInfo>();
					this.addSnsInfos(listObject2);
					return;
				}
				case EventConst.ON_STORAGE_SNSINFO_DEL:
				{
					List<SnsInfo> listObject3 = evtArgs.getListObject<SnsInfo>();
					this.delSnsInfos(listObject3);
					return;
				}
				case EventConst.ON_STORAGE_SNSINFO_MODIFY:
				{
					List<SnsInfo> listObject4 = evtArgs.getListObject<SnsInfo>();
					this.modSnsInfos(listObject4);
					return;
				}
				default:
					return;
				}
				break;
			}
		}
		private void Touch_FrameReported(object sender, TouchFrameEventArgs e)
		{
			if (this.mBIsPageLoaded && !SnsWelcomeCtrl.sBIsShown)
			{
				TouchPointCollection touchPoints = e.GetTouchPoints(null);
				if (1 != touchPoints.get_Count())
				{
					try
					{
						TouchPoint primaryTouchPoint = e.GetPrimaryTouchPoint(null);
						if (primaryTouchPoint != null)
						{
							this.TouchLeave(primaryTouchPoint.get_Position());
						}
					}
					catch (Exception)
					{
						return;
					}
				}
				TouchPoint touchPoint = null;
				try
				{
					touchPoint = e.GetPrimaryTouchPoint(null);
				}
				catch (Exception)
				{
					return;
				}
				if (touchPoint != null)
				{
					if (touchPoint.get_Action() == 1)
					{
						if (this.mBHasExpandedFun && (touchPoint.get_Position().get_X() < this.gridExpandFuncAni.get_Margin().get_Left() || touchPoint.get_Position().get_X() > this.gridExpandFuncAni.get_Margin().get_Left() + this.gridExpandFuncAni.get_ActualWidth() + 100.0 || touchPoint.get_Position().get_Y() < this.gridExpandFuncAni.get_Margin().get_Top() || touchPoint.get_Position().get_Y() > this.gridExpandFuncAni.get_Margin().get_Top() + this.gridExpandFuncAni.get_ActualHeight()))
						{
							this.HideItemFuncs(false);
						}
						this.TouchEnter(touchPoint.get_Position());
						return;
					}
					if (touchPoint.get_Action() == 2)
					{
						this.TouchMove(touchPoint.get_Position());
						return;
					}
					if (touchPoint.get_Action() == 3)
					{
						this.TouchLeave(touchPoint.get_Position());
					}
					return;
				}
				return;
			}
		}
		private void setRefreshCircleOffset(double dOffset)
		{
			this.transRefeshIcon.set_Rotation(-180.0 * (dOffset / 125.0));
			if (dOffset > 78.0)
			{
				dOffset = 78.0;
			}
			this.transRefeshIcon.set_TranslateY(-78.0 + dOffset);
		}
		private void TouchEnter(Point point)
		{
			if (!this.mBIsTopRefreshAniStarted && !this.mBIsEndTopRefreshAniStarted)
			{
				if (this.mBIsInTop)
				{
					this.mBIsDragRefIconStart = true;
					this.mPMouseStart = point;
				}
				return;
			}
		}
		private void TouchLeave(Point point)
		{
			if (this.pageSrc == null)
			{
				return;
			}
			if (!this.mBIsDragRefIconStart)
			{
				if (this.transRefeshIcon.get_TranslateY() != -78.0)
				{
					this.startEndRefreshTopAni();
				}
				return;
			}
			this.mBIsDragRefIconStart = false;
			if (this.mBIsTopRefreshAniStarted || this.mBIsEndTopRefreshAniStarted)
			{
				return;
			}
			if (!this.mBIsInTop)
			{
				if (this.transRefeshIcon.get_TranslateY() != -78.0)
				{
					this.startEndRefreshTopAni();
				}
				return;
			}
			Point point2 = point;
			double arg_56_0 = point2.get_Y();
			double arg_62_0 = this.mPMouseStart.get_Y();
			if (this.mDLastOffset >= 100.0)
			{
				if (this.pageSrc.isPageRefreshing())
				{
					this.startTopRefreshAni();
				}
				this.pageSrc.refreshFirsPage();
				return;
			}
			this.startEndRefreshTopAni();
		}
		private void TouchMove(Point point)
		{
			if (this.mBIsTopRefreshAniStarted || this.mBIsEndTopRefreshAniStarted)
			{
				return;
			}
			if (!this.mBIsDragRefIconStart)
			{
				return;
			}
			if (this.mBIsInTop)
			{
				Point point2 = point;
				if (this.mPMouseStart.get_X() == -1000.0)
				{
					this.mPMouseStart = point2;
					this.mDLastOffset = 0.0;
					return;
				}
				double refreshCircleOffset = point2.get_Y() - this.mPMouseStart.get_Y();
				this.mDLastOffset = refreshCircleOffset;
				this.setRefreshCircleOffset(refreshCircleOffset);
			}
		}
		private void btnComment_Click(object sender, RoutedEventArgs e)
		{
			if (this.mScrollViewer != null && this.mItemExpanded != null)
			{
				this.mItemForComment = this.mItemExpanded;
				this.scrollItemToEnd(this.mItemExpanded.ItemObject as SnsInfo, 0.0);
				base.get_Dispatcher().BeginInvoke(delegate
				{
					this.HideItemFuncs(true);
					this.showInputer();
				});
			}
		}
		private void btnComment_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
		{
			this.transformBtnCmt.set_ScaleX(1.15);
			this.transformBtnCmt.set_ScaleY(1.15);
		}
		private void btnComment_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
		{
			this.transformBtnCmt.set_ScaleX(1.0);
			this.transformBtnCmt.set_ScaleY(1.0);
		}
		private void btnLike_Click(object sender, RoutedEventArgs e)
		{
			if (this.mItemExpanded == null || this.mItemExpanded.ItemObject == null || !(this.mItemExpanded.ItemObject is SnsInfo))
			{
				return;
			}
			SnsInfo snsInfo = this.mItemExpanded.ItemObject as SnsInfo;
			if (snsInfo.nLikeFlag == 0)
			{
				snsInfo.nLikeFlag = 1;
				base.get_Dispatcher().BeginInvoke(delegate
				{
					this.HideItemFuncs(false);
					if (SnsCommentServiceCenter.snsCommentService == null)
					{
						SnsCommentServiceCenter.init();
					}
					SnsCommentServiceCenter.snsCommentService.doSendComment(snsInfo, "", CommentType.MMSNS_COMMENT_LIKE, AddContactScene.MM_ADDSCENE_PF_CONTACT, null, -1);
				});
				return;
			}
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.HideItemFuncs(false);
				SnsInfoMgr.setLikeFlag(snsInfo.nObjectID, false, true);
			});
		}
		private void btnLike_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
		{
			this.transformBtnLike.set_ScaleX(1.15);
			this.transformBtnLike.set_ScaleY(1.15);
		}
		private void btnLike_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
		{
			this.transformBtnLike.set_ScaleX(1.0);
			this.transformBtnLike.set_ScaleY(1.0);
		}
		private void listBoxTimelines_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
		{
			if (this.isInputerShown())
			{
				this.hideInputer();
			}
		}
		private void initUI()
		{
			this.showTimeline(2);
		}
		private void showTimeline(int nCnt = 2)
		{
			List<SnsInfo> list = this.pageSrc.getList(0, nCnt);
			if (list == null)
			{
				this.startTopRefreshAni();
				list = new List<SnsInfo>();
			}
			this.addSnsInfos(list);
		}
		private void scrollItemToEnd(SnsInfo info, double dAppendHeight = 0.0)
		{
			if (this.mScrollViewer == null || this.mListBoxSource == null)
			{
				return;
			}
			double num = 848.0 + dAppendHeight;
			int num2 = this.mListBoxSource.IndexOf(info);
			if (num2 < 1)
			{
				return;
			}
			TimelineItem itemByInfo = this.getItemByInfo(info);
			if (itemByInfo == null)
			{
				if (Debugger.get_IsAttached())
				{
					Debugger.Break();
				}
				return;
			}
			if (itemByInfo.get_ActualHeight() > num)
			{
				this.mScrollViewer.ScrollToVerticalOffset((double)(num2 + 1) - 848.0 / itemByInfo.get_ActualHeight());
				return;
			}
			double num3 = num - itemByInfo.get_ActualHeight();
			double num4 = 0.0;
			int i = num2 - 1;
			while (i >= 0)
			{
				double num5;
				if (i != 0)
				{
					SnsInfo info2 = this.mListBoxSource.get_Item(i);
					TimelineItem itemByInfo2 = this.getItemByInfo(info2);
					if (itemByInfo2 != null && itemByInfo2.mBIsLoaded)
					{
						num5 = itemByInfo2.get_ActualHeight();
					}
					else
					{
						num5 = this.evaluateInfoHeight(info2);
					}
				}
				else
				{
					if (TimelineItemContainer.sAlbumCoverCtrl != null)
					{
						num5 = TimelineItemContainer.sAlbumCoverCtrl.get_ActualHeight();
					}
					else
					{
						num5 = 800.0;
					}
				}
				if (num4 + num5 >= num3)
				{
					double num6 = num5 - (num3 - num4);
					this.mScrollViewer.ScrollToVerticalOffset((double)i + num6 / num5);
					return;
				}
				i--;
				num4 += num5;
			}
		}
		private TimelineItem getItemByInfo(SnsInfo info)
		{
			if (info == null)
			{
				return null;
			}
			return TimelineItem.GetItemByObjId(info.nLocalID);
		}
		private double evaluateInfoHeight(SnsInfo info)
		{
			return TimelineItem.EvaluateInfoHeight(info);
		}
		private void hideAppBar()
		{
			if (this.mBar != null)
			{
				this.mBar.set_IsVisible(false);
			}
		}
		private void showAppBar()
		{
			if (this.mBar != null)
			{
				this.mBar.set_IsVisible(true);
			}
		}
		private void setAppBar(CircleMainPage.CircleMPageBarMode mode)
		{
			if (this.mCurBarmode == mode)
			{
				return;
			}
			switch (mode)
			{
			case CircleMainPage.CircleMPageBarMode.Mode_None:
				this.mBar = null;
				break;
			case CircleMainPage.CircleMPageBarMode.Mode_Defalut:
			{
				this.mBar = new ApplicationBar();
				ApplicationBarIconButton applicationBarIconButton = new ApplicationBarIconButton(new Uri("/Source/Plugin/Sns/Common/Resource/ico_GoTop.png", 2));
				applicationBarIconButton.set_Text(strings.Sns_GoTop);
				applicationBarIconButton.add_Click(new EventHandler(this.btnGoTop_Click));
				this.mBar.get_Buttons().Add(applicationBarIconButton);
				ApplicationBarIconButton applicationBarIconButton2 = new ApplicationBarIconButton(new Uri("/Source/Plugin/Sns/Common/Resource/ico_upload.png", 2));
				applicationBarIconButton2.set_Text(strings.Ablum_Post);
				applicationBarIconButton2.add_Click(new EventHandler(this.btnUpload_Click));
				this.mBar.get_Buttons().Add(applicationBarIconButton2);
				ApplicationBarMenuItem applicationBarMenuItem = new ApplicationBarMenuItem(strings.Album_MessageList);
				applicationBarMenuItem.add_Click(new EventHandler(this.btnSeeMsgList_Click));
				this.mBar.get_MenuItems().Add(applicationBarMenuItem);
				this.mBar.add_StateChanged(new EventHandler<ApplicationBarStateChangedEventArgs>(this.mBar_StateChanged));
				break;
			}
			case CircleMainPage.CircleMPageBarMode.Mode_BigPic:
			{
				this.mBar = new ApplicationBar();
				ApplicationBarMenuItem applicationBarMenuItem2 = new ApplicationBarMenuItem(strings.COM_Save);
				applicationBarMenuItem2.add_Click(new EventHandler(this.btnSave_Click));
				this.mBar.get_MenuItems().Add(applicationBarMenuItem2);
				ApplicationBarMenuItem applicationBarMenuItem3 = new ApplicationBarMenuItem("转发");
				applicationBarMenuItem3.add_Click(new EventHandler(this.btnSendToOther_Click));
				this.mBar.get_MenuItems().Add(applicationBarMenuItem3);
				break;
			}
			}
			base.set_ApplicationBar(this.mBar);
			this.setAppBarStyle(base.get_ApplicationBar());
		}
		private void btnGoTop_Click(object sender, EventArgs e)
		{
			if (this.mScrollViewer == null)
			{
				return;
			}
			this.mScrollViewer.ScrollToVerticalOffset(0.0);
		}
		private void mBar_StateChanged(object sender, ApplicationBarStateChangedEventArgs e)
		{
		}
		public override void setAppBarStyle(IApplicationBar appbar)
		{
			if (appbar == null)
			{
				return;
			}
			base.setAppBarStyle(appbar);
			appbar.set_Opacity(0.99999);
		}
		private void btnUpload_Click(object sender, EventArgs e)
		{
			if (this.isInputerShown())
			{
				this.hideInputer();
			}
			MMMessageBox mMMessageBox = MMMessageBox.Show(strings.ChatSendPicDlgTitle, strings.ChatSendPicDlgInfo, true, strings.ChatSendPicDlgTakePhoto, strings.ChatSendPicDlgImgLib);
			mMMessageBox.ReturnEvent = new DlgReturnEvent(this.SelectPicDlgReturn);
		}
		private void btnSeeMsgList_Click(object sender, EventArgs e)
		{
			if (this.isInputerShown())
			{
				this.hideInputer();
			}
			ToolFunction.GotoPageForUserControl("/Source/Plugin/Sns/Common/UI/SnsMsg/SnsMessageListPage.xaml", null, false);
		}
		private void btnSave_Click(object sender, EventArgs e)
		{
		}
		private void btnSendToOther_Click(object sender, EventArgs e)
		{
		}
		private void startTopRefreshAni()
		{
			if (this.mBIsTopRefreshAniStarted)
			{
				return;
			}
			if (!this.mBIsInTop)
			{
				return;
			}
			this.mBTopRefreshYMoveStarted = true;
			this.stopTopRefreshAni();
			this.stopEndRefreshTopAni();
			this.mBIsTopRefreshAniStarted = true;
			this.mSbTopRefresh = new Storyboard();
			Storyboard storyboard = this.mSbTopRefresh;
			DependencyObject target = this.transRefeshIcon;
			DoubleAnimation doubleAnimation = ToolFunction.createAnimation(new double?(this.transRefeshIcon.get_TranslateY()), 0.0, target, "TranslateY", 300u);
			doubleAnimation.add_Completed(new EventHandler(this.topRefreshYMove_Completed));
			storyboard.get_Children().Add(doubleAnimation);
			doubleAnimation = ToolFunction.createAnimation(new double?(this.transRefeshIcon.get_Rotation()), this.transRefeshIcon.get_Rotation() + 360.0, target, "Rotation", 900u);
			doubleAnimation.set_RepeatBehavior(RepeatBehavior.get_Forever());
			storyboard.get_Children().Add(doubleAnimation);
			storyboard.add_Completed(new EventHandler(this.mSbTopRefresh_Completed));
			storyboard.Begin();
		}
		private void topRefreshYMove_Completed(object sender, EventArgs e)
		{
			this.mBTopRefreshYMoveStarted = false;
			if (this.mBIsNeedEndTopRefresh)
			{
				this.mBIsNeedEndTopRefresh = false;
				this.startEndRefreshTopAni();
			}
		}
		private void mSbTopRefresh_Completed(object sender, EventArgs e)
		{
			this.stopTopRefreshAni();
		}
		private void stopTopRefreshAni()
		{
			if (!this.mBIsTopRefreshAniStarted)
			{
				return;
			}
			this.mBIsTopRefreshAniStarted = false;
			if (this.mSbTopRefresh == null)
			{
				return;
			}
			this.mSbTopRefresh.Stop();
			this.mSbTopRefresh = null;
			this.transRefeshIcon.set_TranslateY(0.0);
		}
		private void startEndRefreshTopAni()
		{
			if (this.mBTopRefreshYMoveStarted)
			{
				this.mBIsNeedEndTopRefresh = true;
				return;
			}
			if (this.mBIsEndTopRefreshAniStarted)
			{
				return;
			}
			this.stopTopRefreshAni();
			this.stopEndRefreshTopAni();
			this.mBIsEndTopRefreshAniStarted = true;
			this.mSbEndTopRefresh = new Storyboard();
			Storyboard storyboard = this.mSbEndTopRefresh;
			DependencyObject target = this.transRefeshIcon;
			DoubleAnimation doubleAnimation = ToolFunction.createAnimation(new double?(this.transRefeshIcon.get_TranslateY()), -78.0, target, "TranslateY", 300u);
			storyboard.get_Children().Add(doubleAnimation);
			doubleAnimation = ToolFunction.createAnimation(new double?(this.transRefeshIcon.get_Rotation()), this.transRefeshIcon.get_Rotation() + 180.0, target, "Rotation", 450u);
			storyboard.get_Children().Add(doubleAnimation);
			storyboard.add_Completed(new EventHandler(this.mSbEndTopRefresh_Completed));
			storyboard.Begin();
		}
		private void mSbEndTopRefresh_Completed(object sender, EventArgs e)
		{
			this.stopEndRefreshTopAni();
		}
		private void stopEndRefreshTopAni()
		{
			if (!this.mBIsEndTopRefreshAniStarted)
			{
				return;
			}
			this.mBIsEndTopRefreshAniStarted = false;
			if (this.mSbEndTopRefresh == null)
			{
				return;
			}
			this.mSbEndTopRefresh.Stop();
			this.mSbEndTopRefresh = null;
			this.transRefeshIcon.set_TranslateY(-78.0);
		}
		private void setScrollHandler()
		{
			if (this.mBIsScrollHandlerSet)
			{
				return;
			}
			this.mBIsScrollHandlerSet = true;
			this.mScrollViewer = (ScrollViewer)UIElementTraveler.FindElementRecursive(this.listBoxTimelines, typeof(ScrollViewer));
			if (this.mScrollViewer == null)
			{
				return;
			}
			FrameworkElement frameworkElement = VisualTreeHelper.GetChild(this.mScrollViewer, 0) as FrameworkElement;
			if (frameworkElement != null)
			{
				VisualStateGroup visualStateGroup = UIElementTraveler.FindVisualState(frameworkElement, "ScrollStates");
				if (visualStateGroup != null)
				{
					visualStateGroup.add_CurrentStateChanging(new EventHandler<VisualStateChangedEventArgs>(this.OnScrollStateChanging));
				}
			}
		}
		private void clearScrollHandler()
		{
			try
			{
				FrameworkElement frameworkElement = VisualTreeHelper.GetChild(this.mScrollViewer, 0) as FrameworkElement;
				if (frameworkElement != null)
				{
					VisualStateGroup visualStateGroup = UIElementTraveler.FindVisualState(frameworkElement, "ScrollStates");
					if (visualStateGroup != null)
					{
						visualStateGroup.remove_CurrentStateChanging(new EventHandler<VisualStateChangedEventArgs>(this.OnScrollStateChanging));
					}
				}
			}
			catch
			{
			}
			this.mScrollViewer = null;
			this.mBIsScrollHandlerSet = false;
		}
		private void OnScrollStateChanging(object sender, VisualStateChangedEventArgs e)
		{
			if (this.mBIsDataCleared)
			{
				return;
			}
			if (e != null && e.get_NewState() != null)
			{
				this.IsScrolling = (e.get_NewState().get_Name() == "Scrolling");
				if (e.get_NewState().get_Name() == "Scrolling")
				{
					this.HideItemFuncs(true);
					this.startListenRendering();
					this.hideToTop();
					if (this.listBoxTimelines == null)
					{
						return;
					}
					this.listBoxTimelines.GetItemsInView();
					if (!this.mBIsScrolling)
					{
						base.Focus();
						this.mBIsScrolling = true;
						return;
					}
				}
				else
				{
					if (e.get_NewState().get_Name() == "NotScrolling")
					{
						if (this.mScrollViewer != null)
						{
							this.mScrollViewer.ScrollToVerticalOffset(this.mScrollViewer.get_VerticalOffset());
						}
						this.showToTop();
						this.stopListenRendering();
						this.mBIsScrolling = false;
						if (this.listBoxTimelines == null)
						{
							return;
						}
						this.listBoxTimelines.UpdateLayout();
					}
				}
				return;
			}
		}
		private void requestHeadImgInCurrView()
		{
			Log.smethod_5("CircleMainPage", "requestHeadImgInCurrView start");
			int num = 7;
			int num2 = (int)this.mScrollViewer.get_VerticalOffset();
			num2 = num2;
			if (num2 < 0)
			{
				num += num2;
			}
		}
		private void startListenRendering()
		{
			if (this.mBIsListendRendering)
			{
				return;
			}
			this.mBIsListendRendering = true;
			CompositionTarget.add_Rendering(new EventHandler(this.CompositionTarget_Rendering));
		}
		private void CompositionTarget_Rendering(object sender, EventArgs e)
		{
			if (TimelineItemContainer.sBIsAlblumCoverLoaded && TimelineItemContainer.sAlbumCoverCtrl != null && TimelineItemContainer.sAlbumCoverCtrl.get_Parent() != null)
			{
				try
				{
					if (TimelineItemContainer.sAlbumCoverCtrl.GetRelativePosition(null).get_Y() > -125.8)
					{
						this.mBIsInTop = true;
					}
					else
					{
						this.mBIsInTop = false;
					}
					return;
				}
				catch (Exception)
				{
					this.mBIsInTop = false;
					return;
				}
			}
			this.mBIsInTop = false;
		}
		private void stopListenRendering()
		{
			if (!this.mBIsListendRendering)
			{
				return;
			}
			this.mBIsListendRendering = false;
			CompositionTarget.remove_Rendering(new EventHandler(this.CompositionTarget_Rendering));
		}
		private void addSnsInfos(List<SnsInfo> listSnsinfo)
		{
			if (listSnsinfo == null)
			{
				return;
			}
			if (this.mListBoxSource == null)
			{
				listSnsinfo.Insert(0, new SnsInfo
				{
					strObjectID = CircleMainPage.cStrAblumCoverID
				});
				listSnsinfo.Add(new SnsInfo
				{
					strObjectID = SnsInfo.toStrID(0uL)
				});
				for (int i = 0; i < listSnsinfo.get_Count(); i++)
				{
					SnsInfo arg_4A_0 = listSnsinfo.get_Item(i);
				}
				this.mListBoxSource = listSnsinfo.ToObservableCollection<SnsInfo>();
				if (this.listBoxTimelines.get_ItemsSource() == null)
				{
					this.listBoxTimelines.set_ItemsSource(this.mListBoxSource);
				}
			}
			else
			{
				this.mergeList(listSnsinfo, false);
			}
			if (this.pageSrc != null && this.mListBoxSource.get_Count() <= 2)
			{
				this.txtNoData.set_Visibility(0);
				return;
			}
			this.txtNoData.set_Visibility(1);
		}
		private void mergeList(List<SnsInfo> listSnsinfo, bool bForceAdd = false)
		{
			if (listSnsinfo == null || listSnsinfo.get_Count() == 0)
			{
				return;
			}
			if (this.mListBoxSource == null)
			{
				return;
			}
			Enumerable.First<SnsInfo>(this.mListBoxSource);
			Enumerable.Last<SnsInfo>(this.mListBoxSource);
			int num = 0;
			using (List<SnsInfo>.Enumerator enumerator = listSnsinfo.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					SnsInfo current = enumerator.get_Current();
					if (this.lastestSnsInfo == null || (current.strObjectID.CompareTo(this.lastestSnsInfo.strObjectID) > 0 && current.strUserName != AccountMgr.curUserName))
					{
						TimeLineObject timeLine = SnsInfoMgr.getTimeLine(current);
						if (timeLine.content != null && timeLine.content.mediaList != null && timeLine.content.mediaList.get_Count() != 0)
						{
							this.lastestSnsInfo = current;
						}
					}
					if ((this.pageSrc == null || this.pageSrc.contains(current) || bForceAdd) && !this.getInfoPInDataSource(current, ref num) && num != -1)
					{
						this.mListBoxSource.Insert(num, current);
					}
				}
			}
		}
		private void delSnsInfos(List<SnsInfo> listSnsinfo)
		{
			if (listSnsinfo != null && this.mListBoxSource != null)
			{
				int num = 0;
				using (List<SnsInfo>.Enumerator enumerator = listSnsinfo.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						SnsInfo current = enumerator.get_Current();
						if (this.getInfoPInDataSource(current, ref num))
						{
							this.mListBoxSource.RemoveAt(num);
						}
					}
				}
				return;
			}
		}
		private void modSnsInfos(List<SnsInfo> listSnsinfo)
		{
			if (listSnsinfo != null && this.mListBoxSource != null)
			{
				int num = 0;
				using (List<SnsInfo>.Enumerator enumerator = listSnsinfo.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						SnsInfo current = enumerator.get_Current();
						if (current.isPrivate())
						{
							List<SnsInfo> list = new List<SnsInfo>();
							list.Add(current);
							this.delSnsInfos(list);
						}
						if (!this.pageSrc.contains(current))
						{
							this.handleUserSendPics(current);
						}
						else
						{
							if (this.getInfoPInDataSource(current, ref num))
							{
								this.copySnsInfo(current, this.mListBoxSource.get_Item(num));
								TimelineItem.RefreshObjIdItem(current, true);
							}
							else
							{
								this.handleUserSendPics(current);
							}
						}
					}
				}
				return;
			}
		}
		private bool handleUserSendPics(SnsInfo snsInfo)
		{
			int num = -1;
			if (snsInfo.strUserName == AccountMgr.strUsrName && SnsInfoMgr.isSentObjectID(snsInfo.nObjectID))
			{
				this.tryFindByLocalID(snsInfo, ref num);
				if (num >= 0)
				{
					int num2 = -1;
					if ((!this.getInfoPInDataSource(snsInfo, ref num2) && num2 == num + 1) || num2 == num)
					{
						this.copySnsInfo(snsInfo, this.mListBoxSource.get_Item(num));
						TimelineItem.RefreshObjIdItem(snsInfo, true);
					}
					else
					{
						this.mListBoxSource.RemoveAt(num);
						List<SnsInfo> list = new List<SnsInfo>();
						list.Add(snsInfo);
						this.mergeList(list, true);
					}
				}
			}
			return true;
		}
		private bool tryFindByLocalID(SnsInfo snsInfo, ref int index)
		{
			if (this.mListBoxSource == null)
			{
				index = -1;
				return false;
			}
			SnsInfo snsInfo2 = Enumerable.FirstOrDefault<SnsInfo>(Enumerable.Where<SnsInfo>(this.mListBoxSource, (SnsInfo snsInfo_0) => snsInfo_0.nLocalID == snsInfo.nLocalID));
			if (snsInfo2 == null)
			{
				return false;
			}
			index = this.mListBoxSource.IndexOf(snsInfo2);
			return true;
		}
		private void copySnsInfo(SnsInfo objNew, SnsInfo objOrigin)
		{
			if (objNew != null && objOrigin != null)
			{
				objOrigin.merge(objNew);
				return;
			}
		}
		public List<ulong> getSnsInfoID()
		{
			if (this.mBIsDataCleared)
			{
				return new List<ulong>();
			}
			if (this.mListBoxSource == null)
			{
				return null;
			}
			int num = Enumerable.Count<SnsInfo>(this.mListBoxSource);
			if (num < 2)
			{
				return null;
			}
			return Enumerable.ToList<ulong>(Enumerable.Select<SnsInfo, ulong>(Enumerable.Take<SnsInfo>(Enumerable.Skip<SnsInfo>(this.mListBoxSource, 1), num - 2), (SnsInfo snsInfo_0) => snsInfo_0.nObjectID));
		}
		private bool getInfoPInDataSource(SnsInfo snsInfo, ref int index)
		{
			if (snsInfo != null && snsInfo.strObjectID != null && this.mListBoxSource != null)
			{
				index = 0;
				using (IEnumerator<SnsInfo> enumerator = this.mListBoxSource.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						SnsInfo current = enumerator.get_Current();
						if (current != null)
						{
							int num = snsInfo.strObjectID.CompareTo(current.strObjectID);
							if (num > 0)
							{
								bool result = false;
								return result;
							}
							if (num < 0)
							{
								index++;
							}
							else
							{
								bool result;
								if (current.nLocalID != snsInfo.nLocalID)
								{
									result = false;
									return result;
								}
								result = true;
								return result;
							}
						}
					}
				}
				index = -1;
				return false;
			}
			index = -1;
			return false;
		}
		private int getInfoIndex(SnsInfo info)
		{
			if (this.mListBoxSource == null)
			{
				return -1;
			}
			if (info == null)
			{
				return -1;
			}
			int num = this.mListBoxSource.IndexOf(info);
			if (num >= 1 && num < this.mListBoxSource.get_Count() - 1)
			{
				return num - 1;
			}
			return -1;
		}
		private int getInfoCnt()
		{
			if (this.mListBoxSource == null)
			{
				return 0;
			}
			return this.mListBoxSource.get_Count() - 2;
		}
		public void ShowBigPic(CirclePagePicsCtrl picsCtrl, int nPicIndex)
		{
			if (picsCtrl == null)
			{
				return;
			}
			WriteableBitmap backgroud = new WriteableBitmap(this.LayoutRoot, null);
			this.ShowBigPic(new ScrollPicsCtrlArgs(picsCtrl, nPicIndex, null, new MMUIEvent(this.scrollPicEnded), backgroud, null));
		}
		private object scrollPicEnded(object obj1, object obj2)
		{
			CircleMainPage.unlockUndo();
			ScrollPicListCtrl instance = ScrollPicListCtrl.getInstance();
			if (instance.get_Parent() != null)
			{
				Panel panel = instance.get_Parent() as Panel;
				panel.get_Children().Remove(instance);
			}
			return null;
		}
		public void ShowBigPic(ScrollPicsCtrlArgs scrollPicsCtrlArgs_0)
		{
			if (!ScrollPicsCtrlArgs.CheckIsInfoOk(scrollPicsCtrlArgs_0))
			{
				return;
			}
			ScrollPicListPage.GotoThisPage(scrollPicsCtrlArgs_0, this.LayoutRoot);
		}
		public void ExpandItemFuncs(TimelineItem item)
		{
			if (this.mBHasExpandedFun)
			{
				this.HideItemFuncs(true);
			}
			this.mBHasExpandedFun = true;
			this.mItemExpanded = item;
			Point relativePosition = item.btnExpand.GetRelativePosition(this.LayoutRoot);
			SnsInfo snsInfo = item.ItemObject as SnsInfo;
			if (snsInfo == null)
			{
				this.HideItemFuncs(false);
				return;
			}
			this.txtFuncCmt.set_Text(strings.Album_Comment_Btn);
			if (snsInfo.nLikeFlag == 0)
			{
				this.imgLike.set_Source(new BitmapImage(new Uri(MMTheme.GetInstance().Sns_ImgPath_like03, 2)));
				this.btnLike.set_IsEnabled(true);
				this.txtFuncLike.set_Text(strings.Album_Like_Btn);
			}
			else
			{
				if (snsInfo.nLikeFlag == 1)
				{
					this.imgLike.set_Source(new BitmapImage(new Uri(MMTheme.GetInstance().Sns_ImgPath_like03, 2)));
					this.btnLike.set_IsEnabled(true);
					this.txtFuncLike.set_Text(strings.Album_Like_Btn_Cancel);
				}
			}
			this.gridExpandClipConer.set_Visibility(1);
			this.gridExpandFuncAni.set_Visibility(0);
			this.gridExpandFuncAni.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
			this.gridExpandFuncAni.InvalidateMeasure();
			if (this.mBIsFisrtExpandItemFuncs)
			{
				this.gridExpandFuncAni.set_Margin(new Thickness(relativePosition.get_X() - this.gridExpandFuncAni.get_ActualWidth(), relativePosition.get_Y() - 21.0, 0.0, 0.0));
			}
			else
			{
				this.gridExpandFuncAni.set_Margin(new Thickness(relativePosition.get_X() - this.gridExpandFuncAni.get_ActualWidth() - 13.0, relativePosition.get_Y() - 21.0, 0.0, 0.0));
			}
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.rectFuncsClip.set_Rect(new Rect(0.0, 0.0, this.gridExpandFuncAni.get_ActualWidth() - 14.0, 70.0));
			});
			this.startItemFuncsAni(true);
			this.mBIsFisrtExpandItemFuncs = false;
		}
		private void startItemFuncsAni(bool bExpand = true)
		{
			this.stopItemFuncsAni();
			this.mBIsItemFuncsAniStarted = true;
			this.mSbExpandImg = new Storyboard();
			Storyboard storyboard = this.mSbExpandImg;
			double num = this.gridExpandFuncAni.get_ActualWidth();
			double double_ = 0.0;
			if (!bExpand)
			{
				num = 0.0;
				double_ = this.gridExpandFuncAni.get_ActualWidth();
				this.rectFuncsClip.set_Rect(new Rect(0.0, 0.0, this.gridExpandFuncAni.get_ActualWidth() - 14.0, 70.0));
				this.gridExpandClipConer.set_Visibility(0);
				this.gridExpandClipConer.set_Opacity(1.0);
			}
			else
			{
				this.gridExpandClipConer.set_Visibility(0);
				this.gridExpandClipConer.set_Opacity(1.0);
			}
			DoubleAnimation doubleAnimation = ToolFunction.createAnimation(new double?(num), double_, this.transformFuncs, "X", 150u);
			storyboard.get_Children().Add(doubleAnimation);
			if (!bExpand)
			{
				doubleAnimation = ToolFunction.createAnimation(new double?(1.0), 0.0, this.gridExpandClipConer, "Opacity", 30u);
				doubleAnimation.set_BeginTime(new TimeSpan?(TimeSpan.FromMilliseconds(120.0)));
				storyboard.get_Children().Add(doubleAnimation);
			}
			storyboard.add_Completed(new EventHandler(this.mSbExpandImg_Completed));
			storyboard.Begin();
		}
		private void mSbExpandImg_Completed(object sender, EventArgs e)
		{
			this.stopItemFuncsAni();
		}
		private void stopItemFuncsAni()
		{
			this.mBIsItemFuncsAniStarted = false;
			if (this.mSbExpandImg == null)
			{
				return;
			}
			this.mSbExpandImg.Stop();
			this.mSbExpandImg = null;
			if (!this.mBHasExpandedFun)
			{
				this.gridExpandFuncAni.set_Visibility(1);
			}
		}
		public void HideItemFuncs(bool bIsHideImediately = false)
		{
			if (bIsHideImediately)
			{
				this.gridExpandFuncAni.set_Visibility(1);
			}
			if (!this.mBHasExpandedFun)
			{
				return;
			}
			this.mBHasExpandedFun = false;
			if (this.mItemExpanded != null)
			{
				this.mItemExpanded.HideItemFuncs();
				this.mItemExpanded = null;
			}
			if (!bIsHideImediately)
			{
				this.startItemFuncsAni(false);
			}
		}
		public static void NotifyIndex(object object_0)
		{
			if (CircleMainPage.sInstance != null)
			{
				CircleMainPage.sInstance.notifyIndex(object_0);
			}
		}
		private void notifyIndex(object object_0)
		{
			if (object_0 != null && object_0 is SnsInfo)
			{
				int infoIndex = this.getInfoIndex(object_0 as SnsInfo);
				if (infoIndex != -1 && this.pageSrc != null)
				{
					this.pageSrc.refreshItem(infoIndex);
				}
			}
		}
		public static FrameworkElement GetListTailCtrl()
		{
			if (CircleMainPage.sCtrlListTail == null)
			{
				SnsLoadingTail snsLoadingTail = new SnsLoadingTail();
				CircleMainPage.sCtrlListTail = snsLoadingTail;
				CircleMainPage.sCtrlListTail.add_LayoutUpdated(new EventHandler(CircleMainPage.sCtrlListTail_LayoutUpdated));
			}
			return CircleMainPage.sCtrlListTail;
		}
		private static void sCtrlListTail_LayoutUpdated(object sender, EventArgs e)
		{
			if (CircleMainPage.IsTailVisible())
			{
				CircleMainPage instance = CircleMainPage.GetInstance();
				if (instance == null)
				{
					return;
				}
				if (instance.pageSrc == null || instance.mListBoxSource == null || instance.mBIsDataCleared)
				{
					return;
				}
				TimeSpan timeSpan = DateTime.get_Now().Subtract(instance.mTimeLastRefEnd);
				instance.mTimeLastRefEnd = DateTime.get_Now();
				if (timeSpan.get_TotalMilliseconds() < 1000.0)
				{
					return;
				}
				instance.pageSrc.refreshItem(instance.getInfoCnt());
				ulong maxObjectID = (instance.mListBoxSource.get_Count() <= 2 || instance.mListBoxSource.get_Item(instance.mListBoxSource.get_Count() - 2) == null) ? 0uL : instance.mListBoxSource.get_Item(instance.mListBoxSource.get_Count() - 2).nObjectID;
				List<SnsInfo> list = instance.pageSrc.getListNearbyObjectID(maxObjectID, 40);
				if (list != null && list.get_Count() > 0)
				{
					instance.addSnsInfos(list);
				}
				else
				{
					if (instance.pageSrc.count() > instance.mListBoxSource.get_Count() - 2)
					{
						list = instance.pageSrc.syncList(instance.getSnsInfoID());
						if (list != null && list.get_Count() > 0)
						{
							instance.mergeList(list, false);
						}
					}
					instance.pageSrc.refreshNextPage();
				}
				if (instance.pageSrc.isRefreshAllPageDone())
				{
					CircleMainPage.SetTailPageEnd();
					return;
				}
				if (instance.pageSrc.isPageRefreshing())
				{
					CircleMainPage.SetTailRefreshing();
					return;
				}
			}
			else
			{
				CircleMainPage.SetTailNotRefreshing();
			}
		}
		public static bool IsTailVisible()
		{
			if (CircleMainPage.sCtrlListTail != null && CircleMainPage.sCtrlListTail.get_Parent() != null)
			{
				CircleMainPage instance = CircleMainPage.GetInstance();
				SnsLoadingTail snsLoadingTail = CircleMainPage.sCtrlListTail as SnsLoadingTail;
				if (snsLoadingTail == null || !snsLoadingTail.mBIsLoaded)
				{
					return false;
				}
				if (instance != null)
				{
					bool result;
					try
					{
						Point relativePosition = CircleMainPage.sCtrlListTail.GetRelativePosition(instance.LayoutRoot);
						if (relativePosition.get_Y() < 0.0 || relativePosition.get_Y() > 800.0)
						{
							return false;
						}
						result = true;
					}
					catch (Exception)
					{
						result = false;
					}
					return result;
				}
			}
			return false;
		}
		public static void SetTailRefreshing()
		{
			if (CircleMainPage.sBIsTailShowRefreshing)
			{
				return;
			}
			CircleMainPage.sBIsTailShowRefreshing = true;
			if (CircleMainPage.sCtrlListTail == null)
			{
				return;
			}
			SnsLoadingTail snsLoadingTail = CircleMainPage.sCtrlListTail as SnsLoadingTail;
			if (snsLoadingTail != null)
			{
				snsLoadingTail.SetStageLoading();
			}
		}
		public static void SetTailNotRefreshing()
		{
			if (!CircleMainPage.sBIsTailShowRefreshing)
			{
				return;
			}
			CircleMainPage.sBIsTailShowRefreshing = false;
			if (CircleMainPage.sCtrlListTail == null)
			{
				return;
			}
			SnsLoadingTail tailCtrl = CircleMainPage.sCtrlListTail as SnsLoadingTail;
			if (tailCtrl != null)
			{
				tailCtrl.get_Dispatcher().BeginInvoke(delegate
				{
					tailCtrl.SetStageDone();
				});
			}
		}
		public static void SetTailPageEnd()
		{
			if (!CircleMainPage.sBIsTailShowRefreshing)
			{
				return;
			}
			CircleMainPage.sBIsTailShowRefreshing = false;
			if (CircleMainPage.sCtrlListTail == null)
			{
				return;
			}
			SnsLoadingTail tailCtrl = CircleMainPage.sCtrlListTail as SnsLoadingTail;
			if (tailCtrl != null)
			{
				tailCtrl.get_Dispatcher().BeginInvoke(delegate
				{
					tailCtrl.SetStageNoMore();
				});
			}
		}
		public static void NotifyLastItemShow()
		{
			if (CircleMainPage.sInstance != null)
			{
				CircleMainPage.sInstance.notifyLastItemShow();
			}
		}
		private void notifyLastItemShow()
		{
		}
		private void tryShowWelcomeCtrl()
		{
			int @int = ConfigMgr.getInt("strKeyNInCircleCnt", 0);
			if (@int < 3)
			{
				SnsWelcomeCtrl.Show(this.LayoutRoot);
			}
		}
		private void disableBackKeyHandler()
		{
			this.mBIsBackKeyEnabled = false;
		}
		private void enableBackKeyHandler()
		{
			this.mBIsBackKeyEnabled = true;
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
			if (SnsRecycleMgr.isRecycling())
			{
				SnsRecycleMgr.doRecycLeEnd();
				cancelEventArgs_0.set_Cancel(true);
				return;
			}
			if (!this.mBIsBackKeyEnabled)
			{
				return;
			}
			if (this.unDoOneThing())
			{
				cancelEventArgs_0.set_Cancel(true);
			}
		}
		public static void lockUndo()
		{
			CircleMainPage.sBIsUndoLocked = true;
		}
		public static void unlockUndo()
		{
			CircleMainPage.sBIsUndoLocked = false;
		}
		public static bool canDoUndo()
		{
			return !CircleMainPage.sBIsUndoLocked;
		}
		private bool unDoOneThing()
		{
			this.mNdoUnDoLevel++;
			if (!CircleMainPage.canDoUndo())
			{
				this.mNdoUnDoLevel--;
				return true;
			}
			if (this.listUndos != null && this.listUndos.get_Count() != 0)
			{
				using (List<CircleMainPage.UnDoDlg>.Enumerator enumerator = this.listUndos.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						CircleMainPage.UnDoDlg current = enumerator.get_Current();
						if (current != null && !(current == new CircleMainPage.UnDoDlg(this.doUndo)) && !this.isThingIgnored(current))
						{
							current();
						}
					}
				}
				this.mNdoUnDoLevel--;
				this.listUndos.Clear();
				return true;
			}
			this.mNdoUnDoLevel--;
			return false;
		}
		private void doUndo()
		{
			if (this.mNdoUnDoLevel > 0)
			{
				return;
			}
			this.mNdoUnDoLevel++;
			if (!CircleMainPage.canDoUndo())
			{
				this.mNdoUnDoLevel--;
				return;
			}
			if (this.listUndos != null && this.listUndos.get_Count() != 0)
			{
				using (List<CircleMainPage.UnDoDlg>.Enumerator enumerator = this.listUndos.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						CircleMainPage.UnDoDlg current = enumerator.get_Current();
						if (current != null && !(current == new CircleMainPage.UnDoDlg(this.doUndo)) && !this.isThingIgnored(current))
						{
							current();
						}
					}
				}
				this.listUndos.Clear();
				this.mNdoUnDoLevel--;
				return;
			}
			this.mNdoUnDoLevel--;
		}
		private void putOneThingToUndo(CircleMainPage.UnDoDlg tUndoDlg)
		{
			if (this.listUndos != null)
			{
				this.listUndos.Add(tUndoDlg);
			}
		}
		private void putOneThingToIgnoreList(object ignoreThing)
		{
			if (this.mUndoIgnore == null)
			{
				this.mUndoIgnore = new List<CircleMainPage.UnDoDlg>();
			}
			if (ignoreThing != null && ignoreThing is CircleMainPage.UnDoDlg)
			{
				this.mUndoIgnore.Add((CircleMainPage.UnDoDlg)ignoreThing);
			}
		}
		private void remFromIgnoreUndoList(object ignoreThing)
		{
			if (this.mUndoIgnore == null)
			{
				return;
			}
			if (ignoreThing != null && ignoreThing is CircleMainPage.UnDoDlg)
			{
				this.mUndoIgnore.Remove((CircleMainPage.UnDoDlg)ignoreThing);
			}
		}
		private void clearIgnoreUndoList()
		{
		}
		private bool isThingIgnored(CircleMainPage.UnDoDlg unDoDlg_0)
		{
			return unDoDlg_0 != null && (this.mUndoIgnore != null && this.mUndoIgnore.Contains(unDoDlg_0));
		}
		private bool isInputerShown()
		{
			return this.mBIsInputerShown;
		}
		private void showInputer()
		{
			this.initInputer();
			this.mBIsInputerShown = true;
			this.mInputer.set_Visibility(0);
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.mInputer.SwitchMode(ChatInputMode.InputTxtMode, false);
			});
			this.hideAppBar();
		}
		private void hideInputer()
		{
			this.mBIsInputerShown = false;
			base.Focus();
			this.mInputer.set_Visibility(1);
			this.mInputer.SwitchMode(ChatInputMode.InputDefault, false);
			this.showAppBar();
		}
		private void doDelayCmts()
		{
			if (SnsCommentServiceCenter.snsCommentService == null)
			{
				SnsCommentServiceCenter.init();
			}
			SnsCommentServiceCenter.snsCommentService.doSendComment(this.mCmtsToSend.mSnsInfo, this.mCmtsToSend.mStrContent, this.mCmtsToSend.mType, this.mCmtsToSend.mScene, null, -1);
			this.mCmtsToSend = null;
		}
		protected override void RootFrameChange(double double_0)
		{
			if (this.mCmtsToSend != null && double_0 <= 0.01)
			{
				this.doDelayCmts();
			}
		}
		private double getCmtsItemToBottomH(int nLevle = 0)
		{
			double num = 800.0 - (this.mPosCommentItem.get_Y() + this.mItemForComment.get_ActualHeight() + 71.0 + 15.0) - (double)this.mNOffSetAppend;
			if (num < 0.0)
			{
				int infoIndex = this.getInfoIndex(this.mItemForComment.ItemObject as SnsInfo);
				if (-1 != infoIndex)
				{
					if (nLevle == 1)
					{
						return 15.0;
					}
					double num2 = 0.0;
					if (this.mItemForComment.get_ActualHeight() > 800.0)
					{
						num2 = (this.mItemForComment.get_ActualHeight() - 800.0) / this.mItemForComment.get_ActualHeight();
					}
					this.mScrollViewer.ScrollToVerticalOffset((double)(infoIndex + 1) + num2);
					this.mPosCommentItem.set_Y(0.0);
					return this.getCmtsItemToBottomH(1);
				}
				else
				{
					num = 15.0;
				}
			}
			return num;
		}
		public void SelectPicDlgReturn(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				this.TakePhoto();
				return;
			case 1:
				this.ChooserPicture();
				return;
			default:
				return;
			}
		}
		private void ChooserPicture()
		{
			MultiPhotoChooser.GoToThisPage(new MultiPhotoChooserConfig
			{
				IsNeedRotate = true,
				CountLimit = 9,
				ForwardPageUri = "/Source/Plugin/Sns/Common/UI/UploadAndPost/SnsPostPage.xaml"
			}, false);
		}
		private void TakePhoto()
		{
			ToolFunction.GotoPageForUserControl("/Source/UI/ImageFilter/ImageFilterPage.xaml", new object[]
			{
				new ImageFilterConfig(null, ImageFilterGetPicMode.GetPicMode_Choose_With_Take, 0, 0, null)
				{
					GetPicMode = ImageFilterGetPicMode.GetPicMode_Take_Photo,
					isSaveToAlbum = ImageFilterMgr.IsSettingAutoSavePhotos(),
					ForwardPageUri = "/Source/Plugin/Sns/Common/UI/UploadAndPost/SnsPostPage.xaml"
				}
			}, false);
		}
		private void showToTop()
		{
		}
		private void mTimerGoTop_Tick(object sender, EventArgs e)
		{
			if (this.mTimerGoTop != null)
			{
				this.mTimerGoTop.Stop();
				this.mTimerGoTop.remove_Tick(new EventHandler(this.mTimerGoTop_Tick));
				this.mTimerGoTop = null;
			}
			this.hideToTop();
		}
		private void hideToTop()
		{
		}
		private void gridGoTop_mClicked(object sender, object args)
		{
			if (this.mScrollViewer == null)
			{
				return;
			}
			this.mScrollViewer.ScrollToVerticalOffset(0.0);
		}
		public void SetTransition()
		{
			TransitionService.SetNavigationOutTransition(this, new NavigationOutTransition
			{
				Forward = new TurnstileTransition
				{
					Mode = TurnstileTransitionMode.ForwardOut
				}
			});
		}
		public void ClearTransition()
		{
			TransitionService.SetNavigationOutTransition(this, null);
		}
		public static void GotoTop()
		{
			if (CircleMainPage.sInstance == null)
			{
				return;
			}
			if (CircleMainPage.sInstance.mScrollViewer == null)
			{
				return;
			}
			CircleMainPage.sInstance.mScrollViewer.ScrollToVerticalOffset(0.0);
		}
		public static void GotoThisPage()
		{
			ToolFunction.GotoPageForUserControl("/Source/Plugin/Sns/Circle/UI/CircleMainPage.xaml", null, false);
		}
		private void initInputer()
		{
			if (this.mBIsInputerInited)
			{
				return;
			}
			this.mBIsInputerInited = true;
			this.mInputer.VoiceSwitchBtn.set_Visibility(1);
			this.mInputer.gridInputArea.set_Width(338.0);
			this.mHeadCtrl = new UserHeadCtrl();
			this.mHeadCtrl.set_Width(53.0);
			this.mHeadCtrl.set_Height(53.0);
			this.mHeadCtrl.set_Margin(new Thickness(20.0, 0.0, 0.0, 0.0));
			this.mHeadCtrl.ItemObject = AccountMgr.strUsrName;
			this.mInputer.inputBk.get_Children().Insert(0, this.mHeadCtrl);
			this.mInputer.bIsWithoutArtSmiley = true;
			this.mInputer.UpdateLayout();
		}
		private object mInputer_mDlgBtnSendText(object sender, object object_0)
		{
			this.mInputer.GetMode();
			if (this.mItemForComment == null)
			{
				return null;
			}
			string text = object_0 as string;
			if (string.IsNullOrEmpty(text))
			{
				return null;
			}
			SnsInfo snsInfo = this.mItemForComment.ItemObject as SnsInfo;
			if (snsInfo == null)
			{
				return null;
			}
			this.mCmtsToSend = new CircleMainPage.CommentTask
			{
				mSnsInfo = snsInfo,
				mStrContent = text,
				mType = CommentType.MMSNS_COMMENT_TEXT,
				mScene = AddContactScene.MM_ADDSCENE_PF_CONTACT,
				mNReplyId = 0,
				mStrReplyName = ""
			};
			this.doDelayCmts();
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.UpdateLayout();
				this.scrollItemToEnd(snsInfo, 0.0);
			});
			return null;
		}
		private object mInputer_mDlgInputAtMember(object sender, object object_0)
		{
			return null;
		}
		private object mInputer_mDlgOnEndPushPage(object sender, object object_0)
		{
			this.hideInputer();
			return null;
		}
		private object mInputer_mDlgOnInputerModeChange(object sender, object object_0)
		{
			return null;
		}
		private object mInputer_mDlgOnRealBoxGotFocus(object sender, object object_0)
		{
			this.isInputFocus = true;
			return null;
		}
		private object mInputer_mDlgOnRealBoxLostFocus(object sender, object object_0)
		{
			this.isInputFocus = false;
			return null;
		}
		private object mInputer_mDlgOnStartPushPage(object sender, object object_0)
		{
			return null;
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Circle/UI/CircleMainPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.listBoxTimelines = (MMListBox)base.FindName("listBoxTimelines");
			this.gridExpandFuncAni = (Grid)base.FindName("gridExpandFuncAni");
			this.gridExpandClipConer = (Grid)base.FindName("gridExpandClipConer");
			this.rectFuncsClip = (RectangleGeometry)base.FindName("rectFuncsClip");
			this.btnLike = (Button)base.FindName("btnLike");
			this.imgLike = (Image)base.FindName("imgLike");
			this.transformBtnLike = (ScaleTransform)base.FindName("transformBtnLike");
			this.txtFuncLike = (TextBlock)base.FindName("txtFuncLike");
			this.btnComment = (Button)base.FindName("btnComment");
			this.imgCmt = (Image)base.FindName("imgCmt");
			this.transformBtnCmt = (ScaleTransform)base.FindName("transformBtnCmt");
			this.txtFuncCmt = (TextBlock)base.FindName("txtFuncCmt");
			this.transformFuncs = (TranslateTransform)base.FindName("transformFuncs");
			this.gridGoTop = (ClickEffectGrid)base.FindName("gridGoTop");
			this.mInputer = (MMInputer)base.FindName("mInputer");
			this.canvasRefreshArea = (Canvas)base.FindName("canvasRefreshArea");
			this.transRefeshIcon = (CompositeTransform)base.FindName("transRefeshIcon");
			this.txtNoData = (TextBlock)base.FindName("txtNoData");
		}
	}
}
